<template>
	<view class="content">
		<view class="list">
			<view class="item" v-for="(item, index) in list" :key="index">
				<view class="left">
					<image :src="item.img"></image>
				</view>
				<view class="right">
					<view class="line">
						<view class="name">{{ item.name }}</view>
						<view class="state">
							<view class="state1" v-if="item.status === 1">已上架</view>
							<view class="state2" v-if="item.status === 2">已下架</view>
						</view>
					</view>
					<view class="time">{{ item.createTime }}</view>
					<view class="text">{{ item.content }}</view>
					<view class="line1">
						<view class="detail" @click="goActivityDetail(item)">查看详情</view>
						<view class="up" v-if="item.status === 2" @click="up(item)">重新上架</view>
						<view class="down" v-if="item.status === 1" @click="down(item)" >下架</view>
						<view class="delete" @click="deleteInfo(item)">删除</view>
					</view>
<!--					<view class="imgLine">-->
<!--						<view v-if="item.imgList.length > 0">-->
<!--							<image v-for="(i, inx) in item.imgList" :key="inx" :src="i.url"></image>-->
<!--						</view>-->
<!--					</view>-->
				</view>
			</view>
		</view>

		<!-- 占位 -->
		<view class="z"></view>
		<view class="btn" v-if="auth===1" @click="goUrl('/pages/my/activityManage/activityRelease')">发布活动</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			activityList: [
				{
					avatar: "http://sni1muz85.hd-bkt.clouddn.com/img/my/avatar.jpeg",
					name: "用户名",
					time: "2020-12-12 12:00",
					state: 0,
					text: "活动内容活动内容活动内容活动内容活动内容活动内容活动内容活动内容活动内容活动内容活动内容活动内容活动内容活动内容活动内容活动内容活动内容",
					imgList: [
						{ url: "http://sni1muz85.hd-bkt.clouddn.com/img/index/swiper2.jpeg" },
						{ url: "http://sni1muz85.hd-bkt.clouddn.com/img/index/swiper1.jpeg" },
						{ url: "http://sni1muz85.hd-bkt.clouddn.com/img/index/swiper2.jpeg" },
					]
				},
				{
					avatar: "http://sni1muz85.hd-bkt.clouddn.com/img/my/avatar.jpeg",
					name: "用户名",
					time: "2020-12-12 12:00",
					state: 1,
					text: "活动内容活动内容活动内容活动内容活动内容活动内容活动内容活动内容活动内容活动内容活动内容活动内容活动内容活动内容活动内容活动内容活动内容",
					imgList: []
				}
			],
      list:[],
      auth:0,
		}
	},
  onShow(){
    this.initData();
  },
  onLoad(){
    // this.initData();

  },
  watch: {
    addressNow: {
      handler(val) {
        console.log("123")
        this.addr = val
      },
      immediate: true,
      deep: true,
    },
  },
	methods: {
		// 路由跳转
		goUrl(url) {
			uni.navigateTo({
				url: url
			})
		},
    initData(){
      this.$api.request({
        url:this.$api.activityList
      }).then(res=>{
        this.list=res.data
      })
      this.$api.request({
        url:this.$api.getInfo
      }).then(res=>{
        this.auth=res.data.auth
      })
    },
    down(item){
      this.$api.request({
        url:this.$api.activityInfo,
        method:"put",
        data:{id:item.id,status:2}
      }).then(res=>{
        uni.showToast({
          title: '已下架',
          duration: 2000
        });
        this.initData();
      })
    },
    up(item){
      uni.navigateTo({
        url: "/pages/my/activityManage/activityRelease?id="+item.id

      })
      // this.$api.request({
      //   url:this.$api.activityInfo,
      //   method:"put",
      //   data:{id:item.id,status:1}
      // }).then(res=>{
      //   uni.showToast({
      //     title: '已上架',
      //     duration: 2000
      //   });
      //   this.initData();
      // })
    },
    deleteInfo(item){
      let that=this
      uni.showModal({
        title: '提示',
        content: '是否删除',
        success: function (res) {
          if (res.confirm) {
            that.$api.request({
              url:that.$api.activityDelete+item.id,
              method:"delete"
            }).then(res=>{
              uni.showToast({
                title: '删除成功',
                duration: 2000
              });
              that.initData();
            })

          } else if (res.cancel) {
          }
        }
      });

    },
		// 跳转活动资讯详情
		goActivityDetail(item) {
			uni.navigateTo({
				url: '/myPage/activity/activityDetail?id='+item.id
			})
		}
	}
}
</script>

<style lang="less" scoped>
@import "@/static/css/app.less";
.content {
	display: flex;
	flex-direction: column;
	align-items: center;

	.list {
		width: 92%;

		.item {
			display: flex;
			margin-top: 20rpx;
			background-color: #fff;
			padding: 30rpx 0;

			.left {
				width: 100rpx;
				margin-left: 20rpx;
				margin-right: 20rpx;

				image {
					width: 100rpx;
					height: 100rpx;
					border-radius: @radius;
				}
			}

			.right {
        width: 78%;
				margin-right: 20rpx;

				.line {
					display: flex;
					justify-content: space-between;
					align-items: center;
					// margin-top: 10rpx;

					.name {
            width: 80%;
						font-size: 32rpx;
            word-wrap: break-word;
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 3;
            overflow: hidden;
            text-overflow: ellipsis;
					}

					.state {
						display: flex;
						font-size: 32rpx;

						.state1 {
							color: #07C160;

						}

						.state2 {
							color: #FF5400;
						}
					}
				}

				.time {
					font-size: 28rpx;
					color: #787878;
					margin-top: 10rpx;
				}

				.text {
					margin-top: 20rpx;
					font-size: 32rpx;
					display: -webkit-box;
					-webkit-box-orient: vertical;
					-webkit-line-clamp: 3;
					overflow: hidden;
					text-overflow: ellipsis;
          word-wrap: break-word;


        }

				.line1 {
					font-size: 32rpx;
					margin-top: 10rpx;
					display: flex;

					.detail {
						color: #07C160;
					}

					.up {
						color: #07C160;
						margin-left: 50rpx;
					}

					.down {
						color: #FF8400;
						margin-left: 50rpx;
					}

					.delete {
						color: #FF4C00;
						margin-left: 50rpx;
					}
				}

				.imgLine {
					display: flex;
					align-items: center;
					margin-top: 20rpx;

					image {
						height: 150rpx;
						width: 150rpx;
						margin-left: 10rpx;
					}
				}
			}
		}
	}

	.z {
		margin-top: 170rpx;
	}

	.btn {
		position: fixed;
		bottom: 120rpx;
		font-size: 32rpx;
		font-weight: bold;
		color: #fff;
		background-color: #07C160;
		border-radius: 50rpx;
		padding: 20rpx 150rpx;
		margin: 80rpx 0 0;
	}
}
</style>